package service

import (
	"BiYeProServer/src/model/dao"
	"BiYeProServer/src/util"
	"github.com/gin-gonic/gin"
)

func Login(ctx *gin.Context){
	// 获取表单数据 tel，password
	username := ctx.PostForm("username")
	password := ctx.PostForm("password")
	if len(username) == 0 || len(password) == 0 {
		util.SetResponse(ctx,50001,false,nil,"用户名不存在")
	} else {
		user := dao.SelectUserByUname(ctx,username)
		if user == nil || user.Username == ""{
			util.SetResponse(ctx,50001,false,nil,"用户名或密码错误")
		} else {
			if user.Password == password {
				util.SetResponse(ctx,200,true,user,"登录成功")
			} else {
				util.SetResponse(ctx,50001,false,nil,"密码错误")
			}
		}
	}
}

